import mapconstant from './map'

const storageNodeKeys = [mapconstant.maptype, mapconstant.lotgla, mapconstant.geodetic, mapconstant.position]

const storageKey = 'map_data'

const mapstorage = {
  setSmall: function (key: string, value: string) {
    if (storageNodeKeys.indexOf(key) != -1) {
      let tmp = uni.getStorageSync(storageKey)
      tmp = tmp ? tmp : {}
      tmp[key] = value
      uni.setStorageSync(storageKey, tmp)
    }
  },
  getSmall: function (key: string) {
    let storageData = uni.getStorageSync(storageKey) || {}
    return storageData[key] == undefined ? '' : storageData[key]
  },
  removeSmall: function (key: string) {
    let storageData = uni.getStorageSync(storageKey) || {}
    delete storageData[key]
    uni.setStorageSync(storageKey, storageData)
  },
  clean: function () {
    uni.removeStorageSync(storageKey)
  }
}

export default mapstorage
